﻿Type.registerNamespace("BM");

BM.FieldConstraints = function(node) {
    this.node = node;
}

BM.FieldConstraints.FieldDataId = '__FieldMenu';

BM.FieldConstraints.getFieldData = function() {
    return document.getElementById(BM.FieldConstraints.FieldDataId);
}

BM.FieldConstraints.get = function() {
    if (BM.FieldConstraints._instance == null) {
        BM.FieldConstraints._instance = new BM.FieldConstraints(BM.FieldConstraints.getFieldData());
    }
    return BM.FieldConstraints._instance;
}

BM.FieldConstraints.prototype = {
    getNode: function() {
        return this.node;
    },

    createOrGetNode: function() {
        if (this.node == null) {
            this.node = document.createElement('div');
            this.node.id = BM.FieldConstraints.FieldDataId;
            this.node.className = "FieldMenu";
        }
        return this.node;
    },

    getItem: function() {
        return this.item;
    },

    setItem: function() {
        this.item = value;
    },

    clear: function() {
        if (this.node == null) return;
        $(this.node).children().remove();
    },

    showConstraint: function(constraint) {
        constraint.appendDescription(this.node);
    },

    show: function(item) {
        if (this.node == null) return;

        this.item = item;
        this.clear();
        for (var i = 0; i < this.getItem().getConstraints().length; i++) {
            this.showConstraint(this.getItem().getConstraints()[i]);
        }

    }
}

BM.FieldConstraints.registerClass("BM.FieldConstraints");